package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;
    /**
     * 新增线索跟进记录
     */
    @Override
    public void add(ClueTrackRecordVo clueTrackRecordVo) {
        //创建一个新增跟进表数据的对象
        TbClueTrackRecord tbClueTrackRecord = new TbClueTrackRecord();
        BeanUtils.copyProperties(clueTrackRecordVo,tbClueTrackRecord);
        //调取工具类获取用户名
        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        //获取当前操作时间
        tbClueTrackRecord.setCreateTime(DateUtils.getNowDate());
        //设置默认type‘0’
        tbClueTrackRecord.setType("0");
        //跟进表添加数据
        tbClueTrackRecordMapper.addClueTrackRecord(tbClueTrackRecord);
        //创建一个修改线索表数据的对象
        TbClue tbClue=new TbClue();
        BeanUtils.copyProperties(clueTrackRecordVo,tbClue);
        //设置他的状态为跟进中：‘2’
        tbClue.setStatus("2");
        tbClue.setId(clueTrackRecordVo.getClueId());

        //修改线索表数据
        tbClueTrackRecordMapper.updateClue(tbClue);

    }
    /**
     * 查询线索跟进
     */
    @Override
    public List<TbClueTrackRecord> select(Long clueId) {

        return tbClueTrackRecordMapper.select(clueId);
    }
}
